import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入注册与登录组件
// import Reg from '@/views/reg'
// import Login from '@/views/login'

// // 导入后台的主页组件
// import Main from '@/views/main'

// // 导入菜单项的组件
// import Home from '@/views/menus/home'
// // 用户
// import UserInfo from '@/views/menus/user/userInfo.vue'
// import UserAvatar from '@/views/menus/user/userAvatar.vue'
// import UserPwd from '@/views/menus/user/userPwd.vue'

// // 文章
// import ArtCate from '@/views/menus/article/artCate.vue'
// import ArtList from '@/views/menus/article/artList.vue'
Vue.use(VueRouter)

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// const routes = [
//   {
//     path: '/',
//     name: 'Home',
//     component: Home
//   },
//   {
//     path: '/about',
//     name: 'About',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
//   }
// ]
// 路由懒加载当需要这个组件时,再去服务器端要组件
const routes = [
  { path: '/reg', component: () => import('@/views/reg') },
  { path: '/login', component: () => import('@/views/login') },
  {
    path: '/',
    component: () => import('@/views/main'),
    redirect: '/home',
    children: [
      { path: 'home', component: () => import('@/views/menus/home') },
      { path: 'user-info', component: () => import('@/views/menus/user/userInfo.vue') },
      { path: 'user-avatar', component: () => import('@/views/menus/user/userAvatar.vue') },
      { path: 'user-pwd', component: () => import('@/views/menus/user/userPwd.vue') },
      { path: 'art-cate', component: () => import('@/views/menus/article/artCate.vue') },
      { path: 'art-list', component: () => import('@/views/menus/article/artList.vue') }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
